package com.ktjiaoyu.crm.controller;

import com.ktjiaoyu.crm.entity.User;
import com.ktjiaoyu.crm.service.UserService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

public class ExampleController {
   private UserService userService;
    @GetMapping(value = "/string")
    public String getString(Model model) {//演示赋值、字符串拼接
        model.addAttribute("userName", "ktjiaoyu");
        return "demo/string";
    }

    @GetMapping(value = "/inline")
    public String inline(Model model) {//演示内联
        model.addAttribute("userName", "ktjiaoyu");
        return "demo/inline";
    }

    @GetMapping(value = "/string")
    public String getString(Model model, HttpServletRequest request) {//演示赋值、字符串拼接
        model.addAttribute("userName", "ktjiaoyu");
        request.setAttribute("test", "request");
        request.getSession().setAttribute("test", "session");
        model.addAttribute("date", new Date());
        return "demo/string";
    }

    @GetMapping(value = "/if")
    public String ifunless(Model model) {//演示条件判断 if/unless
        model.addAttribute("flag", "yes");
        return "demo/if";
    }
    @GetMapping(value = "/list")
    public String list(Model model){//演示for 循环

        List<User> list = userService.findAllUsers();
         model.addAttribute("users",list);
         return "demo/list";
         }
}
